package com.iflytek.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.iflytek.bean.Book;
import com.iflytek.mapper.BookMapper;
import com.iflytek.service.BookService;

@Service
public class BookServiceImpl implements BookService {
	
	@Autowired
	private BookMapper bookMapper;

	@Override
	public List<Book> getAllBooks() {
		return bookMapper.getAllBooks();
	}

	@Override
	public Book findBookById(Integer id) {
		return bookMapper.getBookById(id);
	}

	@Override
	public void saveBook(Book book) {
		bookMapper.insert(book);
	}

	@Override
	public void updateBook(Book book) {
		bookMapper.update(book);
	}

	@Override
	public void deleteBook(Integer id) {
		bookMapper.delete(id);
	}

	@Override
	public Page<Book> getBooksByPage(Integer pageNum, Integer pageSize) {
		//执行分页，返回page对象 page对象中包含了本次分页的信息，页大小，总页数，当前页数，结果
		Page<Book> page=PageHelper.startPage(pageNum, pageSize);
		bookMapper.getAllBooks();
		return page;
	}

}
